package labox.innovation.gameserver.model.actor.knownlist;

import labox.innovation.gameserver.ai.CtrlEvent;
import labox.innovation.gameserver.ai.CtrlIntention;
import labox.innovation.gameserver.model.L2Object;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.actor.instance.FuzeMonsterInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

public class MonsterKnownList extends AttackableKnownList {
	// =========================================================
	// Data Field

	// =========================================================
	// Constructor
	public MonsterKnownList(FuzeMonsterInstance activeChar) {
		super(activeChar);
	}

	// =========================================================
	// Method - Public
	@Override
	public boolean addKnownObject(L2Object object) {
		if (!super.addKnownObject(object))
			return false;
		FuzeMonsterInstance _actor = getActiveChar();
		// Set the L2MonsterInstance Intention to AI_INTENTION_ACTIVE if the state was AI_INTENTION_IDLE
		if (_actor.getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE && object instanceof FuzePcInstance)
			_actor.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
		return true;
	}

	@Override
	public boolean removeKnownObject(L2Object object) {
		if (!super.removeKnownObject(object))
			return false;

		if (!(object instanceof L2Character))
			return true;

		FuzeMonsterInstance _actor = getActiveChar();

		if (_actor.hasAI()) {
			_actor.getAI().notifyEvent(CtrlEvent.EVT_FORGET_OBJECT, object);
		}

		if (getKnownPlayers().isEmpty()) {
			_actor.clearAggroList();
			if (_actor.hasAI())
				_actor.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
		}

		return true;
	}

	// =========================================================
	// Method - Private

	// =========================================================
	// Property - Public
	@Override
	public final FuzeMonsterInstance getActiveChar() {
		return (FuzeMonsterInstance) _activeObject;
	}
}
